package com.pearl.responseEntity;

public class Response<T> {

  public Header header;

  public T value;

  public Response() {
  }

  public Response(T value) {
    this.header = new Header();
    this.value = value;
  }

  public Response(int code, Exception ex) {
    if (ex.getMessage() == null) {
      this.header = new Header(code, ex.toString());
    } else {
      this.header = new Header(code, ex.getMessage());
    }
    this.value = null;
  }

  public Response(int code, String message) {
    this.header = new Header(code, message);
    this.value = null;
  }

  public Response(int code, T value, Exception ex) {
    if (ex.getMessage() == null) {
      this.header = new Header(code, ex.toString());
    } else {
      this.header = new Header(code, ex.getMessage());
    }
    this.value = value;
  }

  public Response(int code, T value, String message) {
    this.header = new Header(code, message);
    this.value = value;
  }

  // 请求头，包含响应码和响应提醒信息
  public static class Header {

    public int code;

    public String message;

    public Header() {
      this.code = 0;
      this.message = "";
    }

    public Header(int code, String message) {
      this.code = code;
      this.message = message;
    }
  }
}


